//
//  SwapSelectCoinCell.swift
//  SCA
//
//  Created by tjun on 2025/9/14.
//

import UIKit
import SnapKit


class SwapCoinModel {
    let coinName: String
    let coin: String
    
    var isSelected: Bool = false
    var subCoinModels: [SwapCoinModel] = []
    
    var coinUrl: String?
    var min: String?
    var decimal: String?
    var swapDecimal: String?
    var fee: String?
    var feeDisp: String?
    var title: String?
    var balance: String?
    var balanceDisp: String?
    var rate: String?
    
    init(coinName: String, coin: String) {
        self.coinName = coinName
        self.coin = coin
    }
}

class SwapCoinCell: BaseTableViewCell {
    
    var model: SwapCoinModel! {
        didSet {
            coinImageView.setImage(url: model.coinUrl)
            titleLabel.text = model.coinName
            containerView.backgroundColor = model.isSelected ? UIColorMake(0x2E3036) : .clear
        }
    }

    private let titleLabel = UILabel(font: UIFontMake(16), textColor: .white)
    private let containerView = UIView()
    private let coinImageView = UIImageView()

    override func setSubView() {
        super.setSubView()

        selectionStyle = .none
 
        backgroundColor = .black
        
        containerView.addCorner(radius: 5)
        contentView.addSubview(containerView)
        containerView.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(6)
            make.top.bottom.equalToSuperview()
        }
        
        containerView.addSubview(coinImageView)
        coinImageView.snp.makeConstraints { make in
            make.left.equalTo(10)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(32)
        }
        
        containerView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalTo(coinImageView.snp.right).offset(8)
            make.centerY.equalToSuperview()
        }
  
    }

}


class BuyPowerCell: BaseTableViewCell {
    
    var model: BuyPowerPaymentOption! {
        didSet {
            coinImageView.setImage(url: model.coinUrl)
            titleLabel.text = model.displayAmount
            containerView.backgroundColor = model.isSelected ? UIColorMake(0x2E3036) : .clear
        }
    }

    private let titleLabel = UILabel(font: UIFontMake(16), textColor: .white)
    private let containerView = UIView()
    private let coinImageView = UIImageView()

    override func setSubView() {
        super.setSubView()

        selectionStyle = .none
 
        backgroundColor = .black
        
        containerView.addCorner(radius: 5)
        contentView.addSubview(containerView)
        containerView.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(6)
            make.top.bottom.equalToSuperview()
        }
        
        containerView.addSubview(coinImageView)
        coinImageView.snp.makeConstraints { make in
            make.left.equalTo(10)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(32)
        }
        
        containerView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalTo(coinImageView.snp.right).offset(8)
            make.centerY.equalToSuperview()
        }
  
    }

}
